package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.log.LogUnionChamberDispatch;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_CHAMBER_DISPATCH_FROM_CROSS, desc = "商会议事厅派遣")
public class UnionChamberDispatchCmdFromCross extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        CrossUnionProto.UnionChamberDispatchCrossRespMsg respMsg = CrossUnionProto.UnionChamberDispatchCrossRespMsg.parseFrom(packet.getBytes());
        int oldPatronsId = respMsg.getOldPatronsId();
        int patronsId = respMsg.getPatronsId();

        DataAnalyticsMgr.trackOreWarAssemblyhall(player, patronsId, Long.valueOf(respMsg.getTotalEarnSpeed()));

        if(oldPatronsId > 0){
            //撤回
            LogMgr.addLogUnionChamberDispatch(new LogUnionChamberDispatch(player.getUserId(), respMsg.getUnionUid(), 0, oldPatronsId, System.currentTimeMillis()));
        }
        //派遣
        LogMgr.addLogUnionChamberDispatch(new LogUnionChamberDispatch(player.getUserId(), respMsg.getUnionUid(), 1, patronsId, System.currentTimeMillis()));
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
